package com.example.its2021606134chh.BusDiyModule;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.widget.ViewPager2;

import com.example.its2021606134chh.HttpUtil;
import com.example.its2021606134chh.R;
import com.example.its2021606134chh.ViewPageAdapter;
import com.example.its2021606134chh.fragment.PersonalInformationFragment;
import com.example.its2021606134chh.fragment.PrepaidRecordsFragment;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayoutMediator;
import com.google.gson.Gson;

import java.util.ArrayList;
import java.util.List;

public class DiyBusOrderActivity extends AppCompatActivity {

    private TabLayout tabLayoutDiy;
    private ViewPager2 viewPagerDiy;
    List<Fragment> fragmentList = new ArrayList<>();
    private ImageView imgBusOrderBack;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_diy_bus_order);
        initView();
        fragmentList.add(WaitPayFragment.newInstance("待支付", ""));
        fragmentList.add(IsPayFragment.newInstance("已支付", ""));
        ViewPageAdapter adapter = new ViewPageAdapter(getSupportFragmentManager(), getLifecycle(), fragmentList);
        viewPagerDiy.setAdapter(adapter);
        new TabLayoutMediator(tabLayoutDiy, viewPagerDiy, true, new TabLayoutMediator.TabConfigurationStrategy() {
            @Override
            public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
                tab.setText(fragmentList.get(position).getArguments().getString("title"));
            }
        }).attach();
        imgBusOrderBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
    }

    private void initData() {
        new Thread(new Runnable() {
            @Override
            public void run() {
                HttpUtil.asyncRequest(new HttpUtil.AsyncCallBack() {
                    @Override
                    public void onFailure(Exception e) {
                    }

                    @Override
                    public void onResponse(String json) {
                        Log.i("TAG", json);
                        Gson gson = new Gson();
                        BusDiy diy = gson.fromJson(json, BusDiy.class);
                        List<BusDiy.ROWSDETAILBean> Temp = diy.getROWS_DETAIL();
                        for (int i = 0; i < Temp.size(); i++) {
                            int flag = Temp.get(i).getFlag();
                            String busstop_start = Temp.get(i).getBusstop_start();
                            String busstop_end = Temp.get(i).getBusstop_end();
                            String busstop_date = Temp.get(i).getBusstop_date();
                        }
                    }
                }, "get_busline_order", new String[]{"UserName"}, "user1");
            }
        }).start();
    }

    private void initView() {
        tabLayoutDiy = (TabLayout) findViewById(R.id.tabLayoutDiy);
        viewPagerDiy = (ViewPager2) findViewById(R.id.viewPagerDiy);
        imgBusOrderBack = (ImageView) findViewById(R.id.imgBusOrderBack);
    }
}